package easytasks.data;

import java.io.Serializable;

public class TaskCategory implements Comparable<TaskCategory>, Serializable
{
	private static final long serialVersionUID = 1L;
	private String id;
	private String name;
	
	public TaskCategory(String name)
	{
		this(null, name);
	}
	
	public TaskCategory(String id, String name)
	{
		setId(id);
		setName(name);
	}
	
	public String getId() { return id; }
	public String getName() { return name; }
	
	public void setId(String value)
	{
		if (value == null) value = "";	
		this.id = value.trim();
	}
	
	public void setName(String name)
	{
		if (name == null) throw new IllegalArgumentException("'name' must be not null");
		if (name.trim().equals("")) throw new IllegalArgumentException("'name' must have 1 or more words.");
		
		this.name = name.trim();
	}
	
	@Override
	public boolean equals(Object o)
	{
		boolean equals = false;
		
		if (o != null && o instanceof TaskCategory)
		{
			TaskCategory other = (TaskCategory)o;
			equals = this.name.equals(other.name);
		}
		
		return equals;
	}
	
	public int compareTo(TaskCategory other) 
	{
		int result = 1;	
		if (other != null) result = this.name.compareTo(other.name);
		
		return result;
	}
	
	@Override
	public String toString()
	{
		return name;
	}
}
